package com.example.mobile2032021606170hsy0415;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import  androidx.recyclerview.widget.RecyclerView;

import org.w3c.dom.Text;

//RecyclerView的适配器
public  class PeopleAdapter extends  RecyclerView.Adapter<PeopleAdapter.ViewHolder>{
    String[] names;
    public  PeopleAdapter(String[] names){
        this.names =names;
    }
    //
    static  class  ViewHolder extends  RecyclerView.ViewHolder{
        TextView tvItemName;
        public  ViewHolder(@NonNull View itemView){
            super(itemView);
            tvItemName = itemView.findViewById(R.id.tv_item_name);
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_main_people,parent,false);
        ViewHolder viewHolder =new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.tvItemName.setText(names[position]);
    }

    @Override
    public int getItemCount() {
        return names.length;
    }
}
